package com.zhs.gccs.view.taskMap;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.zhs.gccs.R;
import com.zhs.gccs.view.BaseView;
import com.zhs.gccs.utils.FlashHelper;
import com.zhs.gccs.utils.OnNoDoubleClickListener;

public class StateButtonView extends BaseView {
    private View ll_state;
    private View v_state;//
    private TextView tv_state;//
    //
    private boolean running = false;
    private boolean isGrey = false;

    public StateButtonView(@NonNull Context context) {
        super(context);
    }

    public StateButtonView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public StateButtonView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void init(Context context, AttributeSet attrs, int defStyleAttr) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_view_state_button, this, true);
//        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomerLogo);
//        String title = typedArray.getString(R.styleable.CustomerInfoItem_preText);
//        typedArray.recycle();
        ll_state = view.findViewById(R.id.ll_state);
        v_state = view.findViewById(R.id.v_state);
        tv_state = view.findViewById(R.id.tv_state);
        ll_state.setOnClickListener(new OnNoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                if(running){//
                    setDefaultState();
                    FlashHelper.getInstance().stopFlick(v_state);
                    if(stateViewListener!=null)stateViewListener.endGj(isGrey);
                }else {
                    setStateBlueStart();
                    if(stateViewListener!=null)stateViewListener.startGj();
                }
            }
        });
        setDefaultState();
    }
    public void setDefaultState(){
        running = false;
        //android:background="@drawable/left_blue_rounded_border_new"
        //android:background="@mipmap/guiji"
        //开始
        // android:textColor="@color/_white"
        ll_state.setBackground(getResources().getDrawable(R.drawable.left_blue_rounded_border_new));
        v_state.setBackground(getResources().getDrawable(R.mipmap.guiji));
        tv_state.setText("开始");
        tv_state.setTextColor(getResources().getColor(R.color._white));
    }
    public void setStateBlueStart(){
        running = true;
        isGrey = false;
        ll_state.setBackground(getResources().getDrawable(R.drawable.left_blue_rounded_border_new));
        v_state.setBackground(getResources().getDrawable(R.drawable.white_round));
        FlashHelper.getInstance().startFlick(v_state);
        tv_state.setText("结束");
        tv_state.setTextColor(getResources().getColor(R.color._white));
    }
    public void setStateGreyStart(){
        running = true;
        isGrey = true;
        ll_state.setBackground(getResources().getDrawable(R.drawable.write_gray_all_rounded_border));
        v_state.setBackground(getResources().getDrawable(R.drawable.black_round));
        FlashHelper.getInstance().startFlick(v_state);
        tv_state.setText("结束");
        tv_state.setTextColor(getResources().getColor(R.color.black_333333));
    }

    private StateViewListener stateViewListener;

    public void setStateViewListener(StateViewListener stateViewListener) {
        this.stateViewListener = stateViewListener;
    }

    public interface StateViewListener{
        void startGj();
        void endGj(boolean hide);
    }

}
